package cn.wetcland.urban.framework.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.wetcland.urban.common.AjaxResponse;
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.wetcland.urban.common.AjaxResponse;
import cn.wetcland.urban.framework.annotation.SaCheckDriverLogin;
import cn.wetcland.urban.framework.dto.*;
import cn.wetcland.urban.framework.service.UtCustomerService;
import cn.wetcland.urban.framework.service.UtDriverService;
import cn.wetcland.urban.framework.utils.StpDriverUtil;
import cn.wetcland.urban.framework.vo.CustomerLoginVO;
import cn.wetcland.urban.framework.vo.DriverLoginVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    public UtCustomerService customerService;

    @Resource
    public UtDriverService driverService;

    @PostMapping("/customerLogin")
    public AjaxResponse customerLogin(@Validated @RequestBody CustomerLoginDTO loginDTO) {
        CustomerLoginVO customerLoginVO = customerService.handleCustomerLogin(loginDTO);
        return AjaxResponse.success(customerLoginVO);
    }

    @PostMapping("/driverLogin")
    public AjaxResponse driverLogin(@Validated @RequestBody DriverLoginDTO loginDTO) {
        DriverLoginVO driverLoginVO = driverService.handleDriverLogin(loginDTO);
        return AjaxResponse.success(driverLoginVO);
    }

    @PostMapping("/customerRegister")
    public AjaxResponse customerRegister(@Validated @RequestBody CustomerRegisterDTO registerDTO) {
        customerService.handleCustomerRegister(registerDTO);
        return AjaxResponse.success();
    }

    @PostMapping("/driverRegister")
    public AjaxResponse driverRegister(@Validated @RequestBody DriverRegisterDTO driverRegisterDTO) {
        driverService.handleDriverRegister(driverRegisterDTO);
        return AjaxResponse.success();
    }

    @SaCheckLogin
    @PostMapping("/customerChangePwd")
    public AjaxResponse customerChangePwd(@Validated @RequestBody CustomerChangePwdDTO customerChangePwdDTO) {
        customerService.handleCustomerChangePwd(customerChangePwdDTO);
        return AjaxResponse.success();
    }

    @SaCheckDriverLogin
    @PostMapping("/driverChangePwd")
    public AjaxResponse driverChangePwd(@Validated @RequestBody CustomerChangePwdDTO customerChangePwdDTO) {
        customerService.handleCustomerChangePwd(customerChangePwdDTO);
        return AjaxResponse.success();
    }

}
